home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1990 / Oct 90 / MacApp.Tech$ 10⁄5⁄90 / 2127-C++ recursion⁄polymo-Oct90 < prev    next >
Encoding:
Text File  |  1991-03-06  |  1.8 KB  |  71 lines  |  [TEXT/GEOL]

  1. Item    6770862                         5-Oct-90        10:43PDT
  2.  
  3. From:   LOCKWOOD                        Savitar, Mike Lockwood,PRT
  4.  
  5. To:     CPLUS.APPLE$                    C++ Interest List--Apple Employees
  6.         CPLUS.DEV$                      C++ Interest List--Developers
  7.         MACAPP.TECH$                    MacApp Technical
  8.  
  9. Sub:    C++ recursion/polymorphis
  10.  
  11. Attn: CPlus Apple
  12. Attn: CPlus Developers
  13. Attn: MacApp Tech
  14. SentBy: Mike Lockwood
  15. Date   10/5/90
  16. Subject    C++ recursion/polymorphism
  17. From   Mike Lockwood
  18. To CPlus Apple
  19.    CPlus Developers
  20.    MacApp Tech
  21.  
  22. C++ recursion/polymorphism bug                 10:29 AM     10/5/90
  23. I have found that C++ v 3.1b4 does not properly handle method dispatching when
  24. the method call is recursive.  This problem occurs with PascalObjects
  25. (descendants of TObject).  I have not tried it with C++ style objects.
  26.  
  27. Here's the scenario:  (The classes have been renamed and greatly simplified
  28. for understandability)
  29.  
  30. // base class
  31. class TListItem : public TObject {
  32.  
  33. TListItem *fNextItem;
  34.  
  35. virtual pascal void Print(void);
  36.  
  37. };
  38.  
  39. // subclass
  40. class TSpecializedListItem : public TListItem {
  41.  
  42. virtual pascal void Print(void);
  43.  
  44. };
  45.  
  46.  
  47. // offending code
  48. pascal void TListItem::Print(void)
  49. {
  50.    // do some printing here
  51.  
  52.    if (fNextItem)
  53.        fNextItem::Print();
  54. }
  55.  
  56. The problem is that the call to fNextItem::Print() always calls
  57. TListItem::Print, even if fNextItem is an instance of TSpecializedListItem!
  58. The compiler generates a JSR directly to TListItem::Print, rather than going
  59. to the Pascal style method dispatching routines.
  60.  
  61. Is this a bug, or a fluke in the C++ language definition?  If this is not a
  62. bug, all the Object Pascal enthusiasts on MacApp.Tech$ hereby have more
  63. ammunition for their cause!
  64.  
  65. Hoping not to stir the soup,
  66.  
  67. Mike Lockwood
  68.  
  69.  
  70.  
  71.